package com.ymatou.iapi.userservice.testcase;

import java.io.IOException;
import java.util.List;
import java.util.Random;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.AddressRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.resp.AddressResp;
import com.ymatou.iapi.userservice.service.AddressRequestDtoCall;
import com.ymatou.iapi.userservice.service.GAddressRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.UserAddress;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;


/**
 * 收货地址上限调整为20个 FreeMaker Template自动生成代码
 */
//TODO 老接口兼容 后续二期会做对应新接口
//Address code 二期去除 产线无用
@TestSuite
public class Ts_AddressRequestDto {

	private static AddressRequestDtoBean arb;
	private static AddressRequestDtoCall arc;
	private static final int ADDRESS_NUM = 20;
	private static final String REQUEST_ADD = "Add";
	private static final String REQUEST_UPDATE = "Update";
	private static final String REQUEST_SETDEFAULT = "SetDefault";
	private static final String REQUEST_MARKDELETE = "MarkDelete";
	private static final int ADDRESS_ACTIVE = 0;
	private static final int ADDRESS_DELETED = -1;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("收货地址上限调整为20个 ");
	}

	@Before
	public void caseUp() {
		arb = new AddressRequestDtoBean();
		arc = new AddressRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(arc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddressRequestDto_001() {
		Logger.start(true, "修改收货地址上限调整为20个成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userid = urrc.getUserid();

			for (int i = 0; i < ADDRESS_NUM; i++) {
				arc = new AddressRequestDtoCall();
				arb.setiAddressId(i);
				arb.setiUserid(userid);
				arb.setsAddressCode("100101");
				arb.setsBaseAddress("autotest" + userid + i);
				arb.setsDetailAddress("autotest" + userid + i);
				arb.setiAction(ADDRESS_ACTIVE);
				arb.setsPostCode("100100");
				arb.setsTelphone("100100");
				arb.setsMobilePhone(TestDataManager.getPhoneNum());
				arb.setsRecipient("autotest");
				arb.setsEmail("autotest@ymatou.com");
				arb.setbIsDefault(false);
				arb.setbXloboChecked(false);
				arb.setAction(REQUEST_ADD);

				arc.setData(arb);
				arc.callService();

				Logger.verifyEquals(true, arc.getSuccess(), "添加地址成功");
				//				Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
				Logger.verifyEquals(ECode.SUCCESS,
						arc.getString("ResponseCode"), "验证Code");
				//				Map address = addressWapper.selectAdressByUserIdAndAddress(userid, "autotest" + userid + i, "autotest" + userid + i);
				JUserWapper addressWapper = new JUserWapper();
				UserAddress address = addressWapper.selectAddress(userid,
						"autotest" + userid + i).get(0);
				Logger.verifyEquals(address.getAddressId().toString(), arc
						.getString("Result").toString(), "验证Addressid");
			}
			arb = new AddressRequestDtoBean();
			arb.setiUserid(userid);
			GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
			gac.setData(arb);
			gac.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "查询地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");
			//{"SuccessMessage":"ok","ResponseCode":200,"Success":true,"Result":[{"iAddressId":868083,"iUserid":30150470,"sAddressCode":"100188","sBaseAddress":"autotest30150470updated","sDetailAddress":"autotest30150470detailupdated","iAction":0,"sPostCode":"610000","sTelphone":"17502838882","sMobilePhone":"17502838882","sRecipient":"autotest","sEmail":"updatedemail@ymatou.com","bIsDefault":true,"bXloboChecked":false,"Action":"Add"}]}
			JsonArray result = gac.getJsonObject().get("Result")
					.getAsJsonArray();
			Logger.verifyEquals(20, result.size(), "验证size");
			List<AddressResp> list = gac.getAddressList();
			for (AddressResp addressResp : list) {
				Logger.debug(FormatUtil.beanToGSONString(addressResp));
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_002() {
		Logger.start(true, "设置默认地址，成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userid = urrc.getUserid();
			JUserWapper addressWapper = new JUserWapper();
			Logger.comment("给用户" + userid + "添加3个地址");
			for (int i = 0; i < 3; i++) {
				arc = new AddressRequestDtoCall();
				arb.setiAddressId(i);
				arb.setiUserid(userid);
				arb.setsAddressCode("100101");
				arb.setsBaseAddress("autotest" + userid + i);
				arb.setsDetailAddress("autotest" + userid + i);
				arb.setiAction(ADDRESS_ACTIVE);
				arb.setsPostCode("100100");
				arb.setsTelphone("100100");
				arb.setsMobilePhone("13888888888");
				arb.setsRecipient("autotest");
				arb.setsEmail("autotest@ymatou.com");
				arb.setbIsDefault(false);
				arb.setbXloboChecked(false);
				arb.setAction(REQUEST_ADD);
				arc.setData(arb);
				arc.callService();
				Logger.verifyEquals(true, arc.getSuccess(), "添加地址成功");
				//				Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
				Logger.verifyEquals(ECode.SUCCESS,
						arc.getString("ResponseCode"), "验证Code");

				UserAddress address = addressWapper.selectAddress(userid,
						"autotest" + userid + i).get(0);
				Logger.verifyEquals(address.getAddressId().toString(), arc
						.getString("Result").toString(), "验证Addressid");
			}
			UserAddress address = addressWapper.selectAddress(userid,
					"autotest" + userid + 1).get(0);
			Logger.comment("设置地址2为默认地址");
			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.getAddressId());
			arb.setiUserid(userid);
			arb.setiAction(ADDRESS_ACTIVE);//action为2表示设置默认地址
			arb.setsEmail("autotest@ymatou.com");
			arb.setAction(REQUEST_SETDEFAULT);
			arb.setbIsDefault(true);
			arc.setData(arb);
			arc.callService();

			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证code");
			Logger.verifyEquals("true", arc.getString("Success"), "验证操作是否成功");
			//			Logger.verifyEquals("提交成功", arc.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyEquals(1,
					(Double.valueOf(arc.getString("Result"))).intValue(),
					"验证result信息");
			addressWapper = new JUserWapper();
			address = addressWapper.selectAddress(userid,
					"autotest" + userid + 1).get(0);
			Logger.verifyEquals(1, address.getIsDefault(), "验证此地址被设置为默认地址");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AddressRequestDto_003() {
		Logger.start(false, "添加已存在的地址，幂等操作");
		try {
			arb.setiAddressId(1);
			arb.setiUserid(new Random().nextInt(99999) + 1);
			arb.setsAddressCode("100101");
			arb.setsBaseAddress("autotest");
			arb.setsDetailAddress("autotest");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("100100");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_ADD);

			arc.setData(arb);
			arc.callService();
			arc.callService();
			//幂等操作
			Logger.verifyEquals(true, arc.getSuccess(), "验证添加");
			//			Logger.verifyIsContains("已处理成功", arc.getLastErrorMessage(), "用户重复添加同一地址提示已处理成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AddressRequestDto_004() {
		Logger.start(false, "不输入用户Id，失败");
		try {
			arb.setiAddressId(100);
			arb.setiUserid(null);
			arb.setsAddressCode("100101");
			arb.setsBaseAddress("autotest");
			arb.setsDetailAddress("autotest");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("100100");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_ADD);

			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(false, arc.getSuccess(), "验证添加失败");
			Logger.verifyIsContains("地址失败", arc.getLastErrorMessage(),
					"userId: null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_005() {
		Logger.start(true, "删除地址，成功");
		try {

			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userid = urrc.getUserid();

			Logger.comment("给用户" + userid + "添加1个收货地址");
			arc = new AddressRequestDtoCall();
			arb.setiAddressId(1);
			arb.setiUserid(userid);
			arb.setsAddressCode("100101");
			arb.setsBaseAddress("autotest" + userid);
			arb.setsDetailAddress("autotest" + userid);
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("100100");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_ADD);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "添加地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			Logger.comment("将该收货地址标志为删除");
			JUserWapper addressWapper = new JUserWapper();
			UserAddress address = addressWapper.selectAddress(userid,
					"autotest" + userid).get(0);

			arb.setiAddressId(address.getAddressId());
			arb.setiUserid(userid);
			arb.setsAddressCode("100101");
			arb.setsBaseAddress("autotest" + userid);
			arb.setsDetailAddress("autotest" + userid);
			arb.setiAction(ADDRESS_DELETED);
			arb.setsPostCode("100100");
			arb.setsTelphone("100100");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_MARKDELETE);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "验证删除成功");

			Logger.verifyEquals("1", arc.getString("Result").toString(),
					"验证修改条数");
			address = addressWapper.selectAddress(userid, "autotest" + userid)
					.get(0);
			Logger.verifyEquals(-1, address.getAddressState(), "验证地址目前是删除状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_006() {
		Logger.start(true, "更新地址信息，成功");
		try {

			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			this.addAddress(userId);
			//			int aid = YmtCallService.addAddress(urrc.getAccessToken(),userId);

			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			String moblie = TestDataManager.getPhoneNum();
			arc = new AddressRequestDtoCall();
			arb = new AddressRequestDtoBean();
			arb.setiAddressId((Integer) address.get(0).getAddressId());
			arb.setiUserid(userId);
			arb.setsAddressCode("100188");
			arb.setsBaseAddress("autotest" + userId + "updated");
			arb.setsDetailAddress("autotest" + userId + "detailupdated");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100112");
			arb.setsTelphone("100101");
			arb.setsMobilePhone(moblie);
			arb.setsRecipient("autotest");
			arb.setsEmail("updatedemail@ymatou.com");
			arb.setbIsDefault(true);
			arb.setAction(REQUEST_UPDATE);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			address = addressWapper.selectAddress(userId, null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals("100101", addressInfo.getTelephone(), "验证电话号码");
			//			Logger.verifyEquals("100188", addressInfo.getAddressId(), "验证Address code");
			Logger.verifyEquals("autotest" + userId + "updated",
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals("autotest" + userId + "detailupdated",
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals(moblie, addressInfo.getMobile(), "验证Mobile信息");
			Logger.verifyEquals("100112", addressInfo.getPostCode(), "验证邮编");
			Logger.verifyEquals("updatedemail@ymatou.com",
					addressInfo.getEmail(), "验证邮箱地址");
			Logger.verifyEquals("autotest", addressInfo.getRecipient(),
					"验证recipient");
			Logger.verifyEquals(1, addressInfo.getIsDefault(), "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_007() {
		Logger.start(true, "更新地址信息号码175段，成功-工单GD201610241679");
		try {

			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			this.addAddress(userId);
			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.get(0).getAddressId());
			arb.setiUserid(userId);
			arb.setsAddressCode("100188");
			arb.setsBaseAddress("autotest" + userId + "updated");
			arb.setsDetailAddress("autotest" + userId + "detailupdated");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("610000");
			arb.setsTelphone("17502838882");
			arb.setsMobilePhone("17502838882");
			arb.setsRecipient("autotest");
			arb.setsEmail("updatedemail@ymatou.com");
			arb.setbIsDefault(true);
			arb.setAction(REQUEST_UPDATE);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");
			address = addressWapper.selectAddress(userId, null);

			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals("17502838882", addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals("100188", addressInfo.getAddressId(), "验证Address code");
			Logger.verifyEquals("autotest" + userId + "updated",
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals("autotest" + userId + "detailupdated",
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals("17502838882", addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals("610000", addressInfo.getPostCode(), "验证邮编");
			Logger.verifyEquals("updatedemail@ymatou.com",
					addressInfo.getEmail(), "验证邮箱地址");
			Logger.verifyEquals("autotest", addressInfo.getRecipient(),
					"验证recipient");
			Logger.verifyEquals(1, addressInfo.getIsDefault(), "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_008() {
		Logger.start(false, "更新地址userid不匹配，失败");
		try {

			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			this.addAddress(userId);
			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			String moblie = TestDataManager.getPhoneNum();
			userId = 1;
			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.get(0).getAddressId());
			arb.setiUserid(userId);
			arb.setsAddressCode("100188");
			arb.setsBaseAddress("autotest" + userId + "updated");
			arb.setsDetailAddress("autotest" + userId + "detailupdated");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100112");
			arb.setsTelphone("100101");
			arb.setsMobilePhone(moblie);
			arb.setsRecipient("autotest");
			arb.setsEmail("updatedemail@ymatou.com");
			arb.setbIsDefault(true);
			arb.setAction(REQUEST_UPDATE);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(false, arc.getSuccess(), "修改地址成功");
			Logger.verifyIsContains("地址用户不匹配",
					arc.getString("LastErrorMessage"), "验证LastErrorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_009() {
		Logger.start(true, "查询地址成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			this.addAddress(userId);
			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);

			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.get(0).getAddressId());
			arb.setiUserid(userId);
			arb.setsAddressCode("100188");
			arb.setsBaseAddress("autotest" + userId + "updated");
			arb.setsDetailAddress("autotest" + userId + "detailupdated");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("610000");
			arb.setsTelphone("17502838882");
			arb.setsMobilePhone("17502838882");
			arb.setsRecipient("autotest");
			arb.setsEmail("updatedemail@ymatou.com");
			arb.setbIsDefault(true);
			arb.setAction(REQUEST_UPDATE);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			address = addressWapper.selectAddress(userId, null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals("17502838882", addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals("100188", addressInfo.get("sAddressCode"), "验证Address code");
			Logger.verifyEquals("autotest" + userId + "updated",
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals("autotest" + userId + "detailupdated",
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals("17502838882", addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals("610000", addressInfo.getPostCode(), "验证邮编");
			Logger.verifyEquals("updatedemail@ymatou.com",
					addressInfo.getEmail(), "验证邮箱地址");
			Logger.verifyEquals("autotest", addressInfo.getRecipient(),
					"验证recipient");
			Logger.verifyEquals(1, addressInfo.getIsDefault(), "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");

			arb = new AddressRequestDtoBean();
			arb.setiUserid(userId);
			GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
			gac.setData(arb);
			gac.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "查询地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");
			//{"SuccessMessage":"ok","ResponseCode":200,"Success":true,"Result":[{"iAddressId":868083,"iUserid":30150470,"sAddressCode":"100188","sBaseAddress":"autotest30150470updated","sDetailAddress":"autotest30150470detailupdated","iAction":0,"sPostCode":"610000","sTelphone":"17502838882","sMobilePhone":"17502838882","sRecipient":"autotest","sEmail":"updatedemail@ymatou.com","bIsDefault":true,"bXloboChecked":false,"Action":"Add"}]}
			JsonObject result = gac.getJsonObject().get("Result")
					.getAsJsonArray().get(0).getAsJsonObject();
			Logger.verifyEquals("17502838882", result.get("sTelphone")
					.getAsString(), "验证电话号码");
			//			Logger.verifyEquals("100188", result.get("sAddressCode").getAsString(), "验证Address code");
			Logger.verifyEquals("autotest" + userId + "updated",
					result.get("sBaseAddress").getAsString(), "验证base address");
			Logger.verifyEquals("autotest" + userId + "detailupdated", result
					.get("sDetailAddress").getAsString(), "验证detail address");
			Logger.verifyEquals("17502838882", result.get("sMobilePhone")
					.getAsString(), "验证Mobile信息");
			Logger.verifyEquals("610000",
					result.get("sPostCode").getAsString(), "验证邮编");
			Logger.verifyEquals("autotest", result.get("sRecipient")
					.getAsString(), "验证recipient");
			Logger.verifyEquals(true, result.get("bIsDefault").getAsBoolean(),
					"验证地址是默认地址");
			Logger.verifyEquals(0, result.get("iAction").getAsInt(), "验证地址状态");
			Logger.verifyEquals("updatedemail@ymatou.com", result.get("sEmail")
					.getAsString(), "验证邮箱地址");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddressRequestDto_010() {
		Logger.start(true, "添加地址成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			AddressRequestDtoCall arc = new AddressRequestDtoCall();
			AddressRequestDtoBean arb = new AddressRequestDtoBean();
			arb.setiAddressId(1);
			arb.setiUserid(userId);
			arb.setsAddressCode("100101");
			arb.setsBaseAddress("autotest" + userId);
			arb.setsDetailAddress("autotestd" + userId);
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("100100");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_ADD);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals(arb.getsTelphone(), addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals(arb.getsAddressCode(), addressInfo.get("sAddressCode"), "验证Address code");
			Logger.verifyEquals(arb.getsBaseAddress(),
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals(arb.getsDetailAddress(),
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals(arb.getsMobilePhone(), addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals(arb.getsPostCode(), addressInfo.getPostCode(),
					"验证邮编");
			Logger.verifyEquals(arb.getsEmail(), addressInfo.getEmail(),
					"验证邮箱地址");
			Logger.verifyEquals(arb.getsRecipient(),
					addressInfo.getRecipient(), "验证recipient");
			Logger.verifyEquals(arb.isbIsDefault(),
					addressInfo.getIsDefault() == 1 ? true : false, "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddressRequestDto_011() {
		Logger.start(true, "不输入email添加地址成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			AddressRequestDtoCall arc = new AddressRequestDtoCall();
			AddressRequestDtoBean arb = new AddressRequestDtoBean();
			arb.setiAddressId(1);
			arb.setiUserid(userId);
			//			arb.setsAddressCode("100101");
			arb.setsBaseAddress("上海市,上海市,黄浦区");
			arb.setsDetailAddress("南京西路1弄1号101");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			//			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			arb.setAction(REQUEST_ADD);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals(arb.getsTelphone(), addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals(arb.getsAddressCode(), addressInfo.get("sAddressCode"), "验证Address code");
			Logger.verifyEquals(arb.getsBaseAddress(),
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals(arb.getsDetailAddress(),
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals(arb.getsMobilePhone(), addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals(arb.getsPostCode(), addressInfo.getPostCode(),
					"验证邮编");
			//			Logger.verifyEquals(arb.getsEmail(), addressInfo.getEmail(), "验证邮箱地址");
			Logger.verifyEquals(arb.getsRecipient(),
					addressInfo.getRecipient(), "验证recipient");
			Logger.verifyEquals(arb.isbIsDefault(),
					addressInfo.getIsDefault() == 1 ? true : false, "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddressRequestDto_012() {
		Logger.start(true, "不输入action默认0,Add,添加地址成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();

			AddressRequestDtoCall arc = new AddressRequestDtoCall();
			AddressRequestDtoBean arb = new AddressRequestDtoBean();
			arb.setiAddressId(1);
			arb.setiUserid(userId);
			//			arb.setsAddressCode("100101");
			arb.setsBaseAddress("上海市,上海市,黄浦区");
			arb.setsDetailAddress("南京西路1弄1号101");
			arb.setiAction(ADDRESS_ACTIVE);
			arb.setsPostCode("100100");
			arb.setsTelphone("");
			arb.setsMobilePhone("13888888888");
			arb.setsRecipient("autotest");
			//			arb.setsEmail("autotest@ymatou.com");
			arb.setbIsDefault(false);
			arb.setbXloboChecked(false);
			//			arb.setAction(REQUEST_ADD);
			arc.setData(arb);
			arc.callService();
			Logger.verifyEquals(true, arc.getSuccess(), "修改地址成功");
			//			Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证Code");

			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			Logger.verifyEquals(arb.getsTelphone(), addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals(arb.getsAddressCode(), addressInfo.get("sAddressCode"), "验证Address code");
			Logger.verifyEquals(arb.getsBaseAddress(),
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals(arb.getsDetailAddress(),
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals(arb.getsMobilePhone(), addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals(arb.getsPostCode(), addressInfo.getPostCode(),
					"验证邮编");
			//			Logger.verifyEquals(arb.getsEmail(), addressInfo.getEmail(), "验证邮箱地址");
			Logger.verifyEquals(arb.getsRecipient(),
					addressInfo.getRecipient(), "验证recipient");
			Logger.verifyEquals(arb.isbIsDefault(),
					addressInfo.getIsDefault() == 1 ? true : false, "验证地址是默认地址");
			Logger.verifyEquals(0, addressInfo.getAddressState(), "验证地址状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_AddressRequestDto_013() {
		Logger.start(true, "添加数据");
		try {

			for (int i = 0; i < 999999; i++) {
				arc = new AddressRequestDtoCall();
				arb.setiAddressId(i);
				arb.setiUserid(i);
				arb.setsAddressCode("100101");
				arb.setsBaseAddress("autotest" + i + i);
				arb.setsDetailAddress("autotest" + i + i);
				arb.setiAction(ADDRESS_ACTIVE);
				arb.setsPostCode("100100");
				arb.setsTelphone("100100");
				arb.setsMobilePhone(TestDataManager.getPhoneNum());
				arb.setsRecipient("autotest");
				arb.setsEmail("autotest@ymatou.com");
				arb.setbIsDefault(false);
				arb.setbXloboChecked(false);
				arb.setAction(REQUEST_ADD);

				arc.setData(arb);
				arc.callService();

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_014() {
		Logger.start(true, "查询地址成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile("175" + TestDataManager.getRandomNum(8));
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			AddressRequestDtoBean addressBean = JUserCallService.initAddressBean(userId);
			JUserCallService.AddressRequestDtoCall(addressBean);

			AddressRequestDtoBean garb = new AddressRequestDtoBean();
			garb.setiUserid(userId);
			GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
			gac.setData(garb);
			gac.callService();
			Logger.verifyEquals(true, gac.getSuccess(), "查询地址成功");
			AddressResp respaddress = gac.getAddressList().get(0);
			JUserWapper addressWapper = new JUserWapper();
			List<UserAddress> address = addressWapper.selectAddress(userId,
					null);
			Logger.verifyEquals(1, address.size(), "验证只有一条地址信息");
			UserAddress addressInfo = address.get(0);
			
			
			Logger.verifyEquals(respaddress.getsTelphone(), addressInfo.getTelephone(),
					"验证电话号码");
			//			Logger.verifyEquals(arb.getsAddressCode(), addressInfo.get("sAddressCode"), "验证Address code");
			Logger.verifyEquals(respaddress.getsBaseAddress(),
					addressInfo.getBaseAddress(), "验证base address");
			Logger.verifyEquals(respaddress.getsDetailAddress(),
					addressInfo.getDetailAddress(), "验证detail address");
			Logger.verifyEquals(respaddress.getsMobilePhone(), addressInfo.getMobile(),
					"验证Mobile信息");
			Logger.verifyEquals(respaddress.getsPostCode(), addressInfo.getPostCode(),
					"验证邮编");
			Logger.verifyEquals(respaddress.getsEmail(), addressInfo.getEmail(),
					"验证邮箱地址");
			Logger.verifyEquals(respaddress.getsRecipient(),
					addressInfo.getRecipient(), "验证recipient");
			Logger.verifyEquals(respaddress.getbIsDefault(),
					addressInfo.getIsDefault() == 1 ? true : false, "验证地址是默认地址");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_015() {
		Logger.start(true, "设置默认地址显示在首位置");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userid = urrc.getUserid();
			JUserWapper addressWapper = new JUserWapper();
			Logger.comment("给用户" + userid + "添加3个地址");
			for (int i = 0; i < 3; i++) {
				arc = new AddressRequestDtoCall();
				arb.setiAddressId(i);
				arb.setiUserid(userid);
				arb.setsAddressCode("100101");
				arb.setsBaseAddress("autotest" + userid + i);
				arb.setsDetailAddress("autotest" + userid + i);
				arb.setiAction(ADDRESS_ACTIVE);
				arb.setsPostCode("100100");
				arb.setsTelphone("100100");
				arb.setsMobilePhone("13888888888");
				arb.setsRecipient("autotest");
				arb.setsEmail("autotest@ymatou.com");
				arb.setbIsDefault(false);
				arb.setbXloboChecked(false);
				arb.setAction(REQUEST_ADD);
				arc.setData(arb);
				arc.callService();
				Logger.verifyEquals(true, arc.getSuccess(), "添加地址成功");
				//				Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
				Logger.verifyEquals(ECode.SUCCESS,
						arc.getString("ResponseCode"), "验证Code");

				UserAddress address = addressWapper.selectAddress(userid,
						"autotest" + userid + i).get(0);
				Logger.verifyEquals(address.getAddressId().toString(), arc
						.getString("Result").toString(), "验证Addressid");
			}
			UserAddress address = addressWapper.selectAddress(userid,
					"autotest" + userid + 1).get(0);
			Logger.comment("设置地址2为默认地址");
			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.getAddressId());
			arb.setiUserid(userid);
			arb.setiAction(ADDRESS_ACTIVE);//action为2表示设置默认地址
			arb.setsEmail("autotest@ymatou.com");
			arb.setAction(REQUEST_SETDEFAULT);
			arb.setbIsDefault(true);
			arc.setData(arb);
			arc.callService();

			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证code");
			Logger.verifyEquals("true", arc.getString("Success"), "验证操作是否成功");


			AddressRequestDtoBean garb = new AddressRequestDtoBean();
			garb.setiUserid(userid);
			GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
			gac.setData(garb);
			gac.callService();
			Logger.verifyEquals(true, gac.getSuccess(), "查询地址成功");
			AddressResp respaddress = gac.getAddressList().get(0);
			Logger.verifyEquals(true, respaddress.getbIsDefault(), "验证第一个是默认地址");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddressRequestDto_016() {
		Logger.start(true, "删除地址不显示");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService
					.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService
					.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result")
					.getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int userid = urrc.getUserid();
			JUserWapper addressWapper = new JUserWapper();
			Logger.comment("给用户" + userid + "添加3个地址");
			for (int i = 0; i < 3; i++) {
				arc = new AddressRequestDtoCall();
				arb.setiAddressId(i);
				arb.setiUserid(userid);
				arb.setsAddressCode("100101");
				arb.setsBaseAddress("autotest" + userid + i);
				arb.setsDetailAddress("autotest" + userid + i);
				arb.setiAction(ADDRESS_ACTIVE);
				arb.setsPostCode("100100");
				arb.setsTelphone("100100");
				arb.setsMobilePhone("13888888888");
				arb.setsRecipient("autotest");
				arb.setsEmail("autotest@ymatou.com");
				arb.setbIsDefault(false);
				arb.setbXloboChecked(false);
				arb.setAction(REQUEST_ADD);
				arc.setData(arb);
				arc.callService();
				Logger.verifyEquals(true, arc.getSuccess(), "添加地址成功");
				//				Logger.verifyEquals("ok", arc.getString("SuccessMessage"), "验证Msg信息");
				Logger.verifyEquals(ECode.SUCCESS,
						arc.getString("ResponseCode"), "验证Code");

				UserAddress address = addressWapper.selectAddress(userid,
						"autotest" + userid + i).get(0);
				Logger.verifyEquals(address.getAddressId().toString(), arc
						.getString("Result").toString(), "验证Addressid");
			}
			UserAddress address = addressWapper.selectAddress(userid,
					"autotest" + userid + 1).get(0);
			Logger.comment("删除地址2");
			arc = new AddressRequestDtoCall();
			arb.setiAddressId((Integer) address.getAddressId());
			arb.setiUserid(userid);
			arb.setiAction(ADDRESS_DELETED);//action为2表示设置默认地址
			arb.setsEmail("autotest@ymatou.com");
			arb.setAction(REQUEST_MARKDELETE);
			arb.setbIsDefault(true);
			arc.setData(arb);
			arc.callService();

			Logger.verifyEquals(ECode.SUCCESS, arc.getString("ResponseCode"),
					"验证code");
			Logger.verifyEquals("true", arc.getString("Success"), "验证操作是否成功");


			AddressRequestDtoBean garb = new AddressRequestDtoBean();
			garb.setiUserid(userid);
			GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
			gac.setData(garb);
			gac.callService();
			Logger.verifyEquals(true, gac.getSuccess(), "查询地址成功");
			AddressResp respaddress = gac.getAddressList().get(0);
			List<AddressResp> list = gac.getAddressList();
			Logger.verifyEquals(2, gac.getAddressList().size(), "验证数量-删除不显示");
			for (AddressResp addressResp : list) {
				Logger.verifyNotEquals(arb.getiAddressId(), respaddress.getiAddressId(), "验证删除不显示");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void addAddress(Integer userId) throws ClientProtocolException,
			IOException {
		AddressRequestDtoCall arc = new AddressRequestDtoCall();
		AddressRequestDtoBean arb = new AddressRequestDtoBean();
		arb.setiAddressId(1);
		arb.setiUserid(userId);
		arb.setsAddressCode("100101");
		arb.setsBaseAddress("autotest" + userId);
		arb.setsDetailAddress("autotest" + userId);
		arb.setiAction(ADDRESS_ACTIVE);
		arb.setsPostCode("100100");
		arb.setsTelphone("100100");
		arb.setsMobilePhone("13888888888");
		arb.setsRecipient("autotest");
		arb.setsEmail("autotest@ymatou.com");
		arb.setbIsDefault(false);
		arb.setbXloboChecked(false);
		arb.setAction(REQUEST_ADD);
		arc.setData(arb);
		arc.callService();
	}
}